package com.whfp.coky.ui.task.vm.fluor

import android.app.Activity
import com.tencent.mmkv.MMKV
import com.whfp.coky.databinding.ActivityFluorSeniorBinding
import com.whfp.coky.other.Constants
import com.whfp.coky.ui.base.BaseDialog
import com.whfp.coky.ui.base.BaseViewModel
import com.whfp.coky.ui.dialog.TipsDialog

/**
 *
 *
 * created by coky on 2022/3/1
 */
class SeniorVM: BaseViewModel<ActivityFluorSeniorBinding>() {
    val mmkv = MMKV.defaultMMKV()

   fun loadView(){
//        加载界面
       vBinding.etLoginUrl.setText(mmkv.decodeString(Constants.URL_LOGIN,Constants.URL_LOGIN))
       vBinding.etFileUpload.setText(mmkv.decodeString(Constants.URL_UPLOAD_FILE,Constants.URL_UPLOAD_FILE))
       vBinding.etDataUpload.setText(mmkv.decodeString(Constants.URL_UPLOAD_DATA,Constants.URL_UPLOAD_DATA))
       vBinding.etUsername.setText(mmkv.decodeString(Constants.URL_USER_NAME,Constants.URL_USER_NAME))
       vBinding.etPassword.setText(mmkv.decodeString(Constants.URL_USER_PWD,Constants.URL_USER_PWD))
   }

    fun doSave(context:Activity){
        mmkv.encode(Constants.URL_LOGIN,vBinding.etLoginUrl.getText().toString())
        mmkv.encode(Constants.URL_UPLOAD_FILE,vBinding.etFileUpload.getText().toString())
        mmkv.encode(Constants.URL_UPLOAD_DATA,vBinding.etDataUpload.getText().toString())
        mmkv.encode(Constants.URL_USER_NAME,vBinding.etUsername.getText().toString())
        mmkv.encode(Constants.URL_USER_PWD,vBinding.etPassword.getText().toString())
        TipsDialog.Builder(context)
            .setIcon(TipsDialog.ICON_FINISH)
            .setMessage("保存成功")
            .setDuration(800)
            .addOnDismissListener(object : BaseDialog.OnDismissListener{
                override fun onDismiss(dialog: BaseDialog?) {
                    context.finish()
                }
            })
            .show()
    }
}